// 填充剩余高度
class InitScreenH {
  constructor() {
    this.clasName = "InitScreenH";
  }

  get getClassName() {
    return this.clasName;
  }

  set setClassName(name) {
    this.clasName = name;
  }

  static install(Vue, options) {
    Vue.directive("init-screen-h", {
      bind(el, binding, vnode, oldVnode) {
        Vue.nextTick(() => {
          //偏差高度，比如header的高度
          let offsetH;
          // 60是 分页的高度和边距
          offsetH = binding.value !== undefined ? binding.value : 60;
          //计算并设置el的高度
          el.style.height =
            window.innerHeight -
            el.getBoundingClientRect().top -
            offsetH +
            "px";
          el.style.overflowY = "auto";
          el.style.overflowX = "hidden";
        });
        window.addEventListener("resize", () => {
          Vue.nextTick(() => {
            let offsetH;
            // 60是 分页的高度和边距
            offsetH = binding.value !== undefined ? binding.value : 60;
            //计算并设置el的高度
            el.style.height =
              window.innerHeight -
              el.getBoundingClientRect().top -
              offsetH +
              "px";
            el.style.overflowY = "auto";
            el.style.overflowX = "hidden";
          });
        });
      },
      componentUpdated(el, binding, vnode, oldVnode) {},
      unbind(el, binding, vnode, oldVnode) {
        window.removeEventListener(
          "resize",
          Vue.nextTick(() => {
            let offsetH;
            // 60是 分页的高度和边距
            offsetH = binding.value !== undefined ? binding.value : 60;
            //计算并设置el的高度
            if (el && el.getBoundingClientRect) {
              el.style.height =
                window.innerHeight -
                el.getBoundingClientRect().top -
                offsetH +
                "px";
              el.style.overflowY = "auto";
              el.style.overflowX = "hidden";
            }
          })
        );
      }
    });
  }
}

export default InitScreenH;
